/**
 * Created by wzh on 2016/8/10.
 */
'use strict'
swan_pc.controller("BusinessContactManageController",function($scope,$rootScope,OrgCompany,OrgContact,OrgOpp,ngDialog){
    $scope.getPages();
    $scope.checkAll=function(yes){
        if (yes) {
            _.forEach(_.filter($scope.orgContactList,$scope.infosFilter),function(item) {
                item.$$checked=true;
            })
        }
        else{
            _.forEach($scope.orgContactList,function(item) {
                item.$$checked=false;
            })
        }
    }
    $scope.editItemDetail=function(id) {
        OrgContact.queryAll({cid: id}, function (result) {
            if (result.businessInfo == null) result.businessInfo = {}
            if (result.employeeInfo == null) result.employeeInfo = {}
            $scope.presentOrgContact = result;
            $scope.orgContactPointer={
                orgContactBaseInfo:result.baseInfo,
                orgContactBusinessInfo:result.businessInfo,
                orgContactBaseInfoAddresss:result.baseInfo.addresss,
                orgContactBaseInfoMobileNumberList:result.baseInfo.mobileNumberList,
                orgContactBaseInfoEmailList:result.baseInfo.emailList,
                orgContactBaseInfoFixedNumberList:result.baseInfo.fixedNumberList,
                orgContactEmployeeInfo:result.employeeInfo,
                //orgContactCensusInfo:result.censusInfo,
                //orgContactCensusInfoBankAccounts:result.censusInfo.bankAccounts,
                //orgContactCensusInfoAattachments:result.censusInfo.aattachments,
                orgContactEducationHistorys:result.educationHistorys,
                orgContactWorkHistorys:result.workHistorys
            }
            ngDialog.open({
                templateUrl:"scripts/components/MyOrganization/businessInfo/businessContactManage/businessContactDetail.html",
                scope:$scope,
                controller:["$scope",function($scope){
                    $scope.module=$scope.orgContactStruct[0].blockName
                    /*$scope.updateOrgContact=function(){
                        OrgContact.update({},$scope.presentOrgContact,function(result){
                            alert("保存成功");
                            $scope.edit=false;
                            $scope.resetOrgContact(result.id)
                        })
                    }
                    $scope.resetOrgContact=function(id){
                        OrgContact.queryAll({cid: id}, function (result) {
                            $scope.presentOrgContact = result;
                        })
                    }
                    $scope.addElement=function(array){
                        array.push({});
                    }
                    $scope.edit=false;
                    $scope.module=$scope.orgContactStruct[0].blockName
                    //脏检查
                    $scope.dirty={
                        orgContactBaseInfo:false,
                        orgContactBusinessInfo:false,
                        orgContactBaseInfoAddresss:false,
                        orgContactBaseInfoMobileNumberList:false,
                        orgContactBaseInfoEmailList:false,
                        orgContactBaseInfoFixedNumberList:false,
                        orgContactEmployeeInfo:false,
                        //orgContactCensusInfo:false,
                        //orgContactCensusInfoBankAccounts:false,
                        //orgContactCensusInfoAattachments:false,
                        orgContactEducationHistorys:false,
                        orgContactWorkHistorys:false,
                    }
                    $scope.initDirty=function() {
                        $rootScope.orgContactDirty = false;
                        $scope.dirty.orgContactBaseInfo=false;
                        $scope.dirty.orgContactBusinessInfo=false;
                        $scope.dirty.orgContactBaseInfoAddresss=false;
                        $scope.dirty.orgContactBaseInfoMobileNumberList=false;
                        $scope.dirty.orgContactBaseInfoEmailList=false;
                        $scope.dirty.orgContactBaseInfoFixedNumberList=false;
                        $scope.dirty.orgContactEmployeeInfo=false;
                        //$scope.dirty.orgContactCensusInfo=false;
                        //$scope.dirty.orgContactCensusInfoBankAccounts=false;
                        //$scope.dirty.orgContactCensusInfoAattachments=false;
                        $scope.dirty.orgContactEducationHistorys=false;
                        $scope.dirty.orgContactWorkHistorys=false;
                    }
                    $scope.dirtySet=function(index){
                        $rootScope.orgContactDirty=true;
                        $scope.dirty[index]=true;
                    }
                    $scope.dirtyGet=function(index){
                        return $scope.dirty[index];
                    }*/
                }]
            })
        }, function () {
            $scope.presentOrgContact = undefined;
        })
    }
})
